export function throttle(fn,wait){
    let previous = 0
    return function(){
        let now = new Date().getTime()
        if(now-previous>wait){
            fn.apply(this,arguments)
            previous = now
        }
    }
}

export function debounce(fn,wait){
    let timer 
    return function(){
        clearTimeout(timer)
        timer = setTimeout(() => {
            fn.apply(this,arguments)
        }, wait);
    }
}
/**
 * 判断鼠标在canvas的第几象限
 * @param {*} x 
 * @param {*} y 
 */
export function calQuadrant(x,y){
    var widthSemi = window.canvasNode.width/2
    var heightSemi = window.canvasNode.height/2
    if(x<=widthSemi && y<=heightSemi){
        return 2
    }
    if(x>widthSemi && y<=heightSemi){
        return 1
    }
    if(x>widthSemi && y>heightSemi){
        return 4
    }
    if(x<=widthSemi && y>heightSemi){
        return 3
    }
}

export function clearCanvas(){
    window.canvas2Dctx.clearRect(0,0,
        window.canvasNode.width,
        window.canvasNode.height
    )
    
}